{% extends "master.html" %}
{% load common_extras %}
{% block head_ext %}
<script type="text/javascript" src="/site_media/js/rpc.js"></script>
<script type="text/javascript" src="/site_media/js/jquery/ui/ui.core.js"></script>
<script type="text/javascript" src="/site_media/js/jquery/ui/ui.dialog.js"></script>
<link rel="stylesheet" href="/site_media/js/jquery/ui/themes/flora/flora.all.css" type="text/css" media="screen" title="no title" />
<meta http-equiv="content-type" content="text/html; charset=utf8" />
<script type="text/javascript">
     
  service = new rpc.ServiceProxy("/services/admin/", {asynchronous:false, methods: ['set_privilege']});
  
  	$(document).ready(function(){
	  $('a.set,a.all,a.clean').click(function(){
	         var id = $(this).parent().parent().attr('id');
	         var privilege_id = $(this).parent().parent().attr('privilege_id');
	         var privilege_value = 1;
	         var cls = $(this).attr("class");
	         if(cls == 'all'){
	             privilege_value = 2310;
	         }else if(cls == 'clean'){
	             privilege_value = 0;
	         }else{
	             $('.set' + id + ":checked").each(function(){
	                 var v = $(this).val();
	                 privilege_value *= parseInt(v);
	             });
	         }
	         try{
	            service.set_privilege({'id': privilege_id, 'page_id': id, 'privilege_value': privilege_value, 'user_id': {{user_id}}})
	            window.location.reload() ;
	         }catch(e){
	            alert(e.message);
	         }
	    });
  });
  
</script>
{% endblock %}
{% block title %}权限修改{% endblock %}
{% block content %}
<input type="button" class="invite" value="邀请加入"/>
<table cellspacing="1" class="tablesorter">
  <thead>
    <th>ID </th>
    <th>页面名称</th>
    <th>查看</th>
    <th>新建</th>
    <th>更新</th>
    <th>删除</th>
    <th>审核</th>
    <th>设置</th>
  </thead>
  <tbody>
    {% if infos %}
      {% for info in infos %}
       <tr id="{{info.id}}" privilege_id="{{info.privilegeId}}">
         <td>{{info.id}}</td>
         <td>{{info.name}}</td>
         <td><input type="checkbox" value="2" class="set{{info.id}}" {{ info.privilege_value|check_is_privileges:2 }}></td>
         <td><input type="checkbox" value="3" class="set{{info.id}}" {{ info.privilege_value|check_is_privileges:3 }}></td>
         <td><input type="checkbox" value="5" class="set{{info.id}}" {{ info.privilege_value|check_is_privileges:5 }}></td>
         <td><input type="checkbox" value="7" class="set{{info.id}}" {{ info.privilege_value|check_is_privileges:7 }}></td>
         <td><input type="checkbox" value="11" class="set{{info.id}}" {{ info.privilege_value|check_is_privileges:11 }}></td>
         <td>
            <a href="#" class="set">设置</a>&nbsp;&nbsp;
            <a href="#" class="all">分配全部权限</a>&nbsp;&nbsp;
            <a href="#" class="clean">取消全部权限</a>
         </td>
       </tr>
      {% endfor %}
    {% endif %}
     <tr style="display:none"><td id="pageLink" colspan="12"></td></tr>
  </tbody>
</table>
{% endblock %}